﻿using Microsoft.Extensions.Configuration;
using Simple.Tools;
using SimpleSaas.Common;
using SimpleSaas.Common.Execption;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace SimpleSaas.Common
/// <summary>
/// 版 本 钢易智企2.0 V 2.0.0 钢易智企2.0
/// Copyright (c) 2023 杭州钢易科技有限公司
/// 创建人：曾东明
/// 日 期：2024
/// 描 述：
/// </summary>
{
	/// <summary>
	/// 需要在使用filter
	/// 
	/// </summary>
	public static class App
	{
		/// <summary>
		/// 
		/// </summary>
		public static IConfiguration Configuration { get; set; }

		/// <summary>
		/// 每次请求保存一份
		/// 1.需要使用Parameter filter
		/// 2.初始化是在控制器调用service方法之前完成
		/// 
		/// </summary>

		public static ThreadLocal<LoginUserInfo> UserInfo = new ThreadLocal<LoginUserInfo>();

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		/// <exception cref="BusinessException"></exception>
		public static long GetUserId()
		{
			return GetUserInfo().UserId;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		/// <exception cref="BusinessException"></exception>
		public static LoginUserInfo GetUserInfo()
		{
			LoginUserInfo userInfo = UserInfo.Value;
			if (SimpleCheck.IsNotNull(userInfo))
			{
				return userInfo;
			}
			throw new BusinessException("请重新登录,获取用户信息失败!");
		}

	}
}